﻿using ChestPainCenterSystem.Areas.ChestPainCenter.Models;
using ChestPainCenterSystem.Code.Bll;
using ChestPainCenterSystem.Core;
using ChestPainCenterSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChestPainCenterSystem.Areas.ChestPainCenter.Controllers
{
    public class DisRecord2Controller : BaseController
    {
        // 临床事件相关
        // GET: /ChestPainCenter/DisRecord2/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Edit(int id=0)
        {
            linchuangshijian linchuangshijian = new linchuangshijian();
            if (id > 0)
            {
                OperateResult resultInfo = LinChuangShiJian.GetlinchuangshijianList(id.ToString(),1,1, "");
                if (resultInfo.Result == 1)
                {
                    var d = JsonConvert.DeserializeObject<dynamic>(resultInfo.Body.ToString());
                    linchuangshijian = JsonConvert.DeserializeObject<linchuangshijian>(JsonConvert.SerializeObject(d.Rows[0]));   
                }
            }
            ViewBag.Linchuangshijian = linchuangshijian;
            return View();
        }

        public ContentResult Save()
        {
            linchuangshijian lcsj = new linchuangshijian();
            lcsj.code = Request["txtCode"];
            lcsj.create_time = DateTime.Now;
            lcsj.Id = Convert.ToInt32(Request["txtId"]);
            lcsj.IsDelete = 0;
            lcsj.name = Request["txtName"];
            lcsj.zl_Ids = Request["txtzljlId"];
            lcsj.zl_Names=Request["txtzljlName"];
            lcsj.zl_code = Request["txtzljlCode"];
            lcsj.create_user = loginUser.Name;
            OperateResult resultInfo = LinChuangShiJian.Setlinchuangshijian(JsonHelper.JsonDate(lcsj));
            return JsonDate(resultInfo);
        }

        public ActionResult Bind()
        {
            OperateResult result = ZhenLiaoJiLu.GezhenliaojiluList(1, 10, "");
            
            List<object> vals = new List<object>();
            if (result.Result == 1)
            {
                var listData = JsonConvert.DeserializeObject<dynamic>(result.Body.ToString());                
                foreach (var item in listData.Rows)
                {

                    vals.Add(item.Id + "," + item.code + "," + item.name);
                }
            }
           
            ViewBag.vals = vals;
            return View();
        }
        public ActionResult Search()
        {
            string pageIndex = Request["page"];
            string pageSize = Request["pagesize"];
            string name = Request["txtName"];
            OperateResult resultInfo = LinChuangShiJian.GetlinchuangshijianList(string.Empty, Convert.ToInt32(pageIndex), Convert.ToInt32(pageSize), name);
            string NoDate = "{Rows:[],Total:0}";
            if (resultInfo.Result == 1)
            {
                var listData = JsonConvert.DeserializeObject<dynamic>(resultInfo.Body.ToString());
                return JsonDate(listData);
            }
            return Content(NoDate);


        }
    }
}
